package com.lb.activity.rest;

import com.lb.activity.po.ExaminePermission;
import com.lb.activity.po.ExamineRole;
import com.lb.activity.service.ExaminePermissionService;
import com.lb.activity.util.ResultUtil;
import com.lb.activity.vo.PermissionVo;
import com.lb.activity.vo.RoleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author liubin
 */
@RestController
@RequestMapping("examine/permission")
@Api(value = "审批权限")
@Slf4j
public class ExaminePermissionController {


    @Autowired
    private ExaminePermissionService examinePermissionService;

    @GetMapping("toPermission")
    @ApiOperation(value = "跳转到权限页面")
    public ModelAndView toRole(){
        return new ModelAndView("examine/permission/permission");
    }

    @GetMapping("toAdd")
    @ApiOperation(value = "跳转到权限添加页面")
    public ModelAndView toAdd(){
        return new ModelAndView("examine/permission/permission-add");
    }

    @GetMapping("list")
    @ApiOperation(value = "分页查询权限",notes = "分页查询")
    public ResultUtil list(PermissionVo permissionVo){
        ResultUtil resultUtil =  examinePermissionService.list(permissionVo);
        return resultUtil;
    }

    @PostMapping("add")
    @ApiOperation(value = "添加权限")
    public ResultUtil add(ExaminePermission permission){
        ResultUtil resultUtil = examinePermissionService.add(permission);
        return resultUtil;
    }

    @GetMapping("toUpdate")
    @ApiOperation(value = "跳转到更新页面",notes = "传递id，查询权限返回")
    public ModelAndView toUpdate(Long id){
        ModelAndView modelAndView = new ModelAndView();
        ExaminePermission permission = examinePermissionService.getOne(id);
        modelAndView.setViewName("examine/permission/permission-update");
        modelAndView.addObject("permission",permission);
        return modelAndView;
    }

    @PostMapping("update")
    @ApiOperation(value = "更新权限")
    public ResultUtil update(ExaminePermission permission){
        ResultUtil resultUtil = examinePermissionService.update(permission);
        return resultUtil;
    }

    @PostMapping("delete")
    @ApiOperation(value = "删除权限")
    public ResultUtil delete(Long id){
        ResultUtil resultUtil = examinePermissionService.delete(id);
        return resultUtil;
    }

    @PostMapping("changeStatus")
    @ApiOperation(value = "修改权限的状态")
    public ResultUtil changeStatus(Long id,boolean boolStatus){
        ResultUtil resultUtil = examinePermissionService.changeStatus(id,boolStatus);
        return resultUtil;
    }

}
